import Pinyin from "./spell"

export default function(list){
    let pinyinArray = []
    let reg = /^[A-Za-z]*$/;
    list?.map((v)=>{
      var ken = Pinyin.getSpell(v.nick_name ? v.nick_name[0] : v.group_name[0], function (charactor, spell) {
        return spell[1];
      })
      pinyinArray.push({...v, spell:reg.test(ken[0])?ken[0].toUpperCase():'#'})
    })
  
    let map = {
      title: '',
      datas: []
    }
    pinyinArray.forEach((item) => {
      if (!map[item.spell]) {
        map[item.spell] = {
          title: item.spell,
          datas: []
        }
      }
      map[item.spell].datas.push(item)
    })
    var turn = new Array()
    var letters = "ABCDEFGHIJKLNMOPQRSTUVWXYZ#".split('');
    for (var i = 0; i <= letters.length; i++) {
      if (map[letters[i]]) {
        turn.push(map[letters[i]])
      }
    }
    
    return turn
}
